package com.ajax;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wzm
 * @create 2023-05-15 15:26
 */
@WebServlet("/ajax01")
public class AjaxServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      req.setCharacterEncoding("utf-8");
      resp.setContentType("text/html;charset=utf-8");

      //获取Ajax携带的数据
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println("password = " + password);
        System.out.println("username = " + username);


        resp.getWriter().write("恭喜，"+username+"ajax访问成功！！");

    }
}
